package com.sias.swagger.exception;

import com.sias.swagger.common.BaseResponse;
import com.sias.swagger.common.ErrorCode;
import com.sias.swagger.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 吴文杰
 * @version 1.0
 * @createTime 2023-05-19 20:38:31
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

  @ExceptionHandler(BusinessException.class)
  public BaseResponse<?> businessExceptionHandler(BusinessException e) {
    log.error("BusinessException", e);
    return ResultUtils.error(e.getCode(), e.getMessage());
  }

  @ExceptionHandler(RuntimeException.class)
  public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
    log.error("RuntimeException", e);
    return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
  }

}
